package com.ssh.test;

public class aa {
	public static void main(String[] args) {
		new SingleThread("A").start();
		new SingleThread("B").start();
		new SingleThread("C").start();
	}
}

class SingleThread extends Thread {
	private static String curr = "A";
	private int count = 0;
	private String threadName;

	public SingleThread(String threadName) {
		this.threadName = threadName;
	}

	@Override
	public void run() {
		for (; count < 10;) {
			synchronized (curr) {
				if (threadName.equals(curr)) {
					System.out.print(threadName);
					count++;
					if (curr.equals("A")) {
						curr = "B";
					}
					else if (curr.equals("B")) {
						curr = "C";
					}
					else if (curr.equals("C")) {
						curr = "A";
					}
				} else {
//					System.out.println("i am " +threadName +"--curr"+curr);
				}
			}
		}
	}
}